package com.xxx.common.model;

import com.xxx.para.ParametersUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 分页请求参数
 *
 * @Author: shixx
 * @Date: 2018/5/24 15:47
 */
@ApiModel("分页请求参数")
@Data
@EqualsAndHashCode(callSuper =false)
public class ReqPageInfoVO extends ReqUserId {

    @ApiModelProperty(value = "当前页")
    private Integer currentPage = 1;

    @ApiModelProperty(value = "显示的条数")
    private Integer showCount = 10;

    @ApiModelProperty(value = "当前分页的时间戳")
    private Long timeStamp;

    @ApiModelProperty(value = "排序字段",hidden = true)
    private String sortField = "";

    @ApiModelProperty(value = "排序顺序  desc|asc",hidden = true)
    private String sortOrder = "";

    @ApiModelProperty(value="查询开始位置", hidden = true)
    private Integer currentResult;

    @ApiModelProperty(value="是否查询全部内容")
    private Integer isShowAll = 0;

    public Integer getCurrentResult() {

        currentPage = ParametersUtil.isNull(currentPage) && currentPage >0 ? 1 : this.currentPage;
        showCount = ParametersUtil.isNull(showCount)  && currentPage >0? 1 : this.showCount;

        // 计算从第几条获取数据
        currentResult = (currentPage - 1) * showCount;
        return currentResult;
    }

    public Long getTimeStamp(){
        if (timeStamp != null && timeStamp.toString().length() <= 10){
            timeStamp = timeStamp * 1000;
        }
        return timeStamp;
    }
}
